/**
 * @回到顶部按钮
 */
import React, { useEffect, useState } from 'react';
import style from "./tojumper.less";
import { VerticalAlignTopOutlined } from '@ant-design/icons';
function TopJumper() {
    const [show, switchShow] = useState(false); // 设置状态

    useEffect(() => {
        const listener = () => {
            switchShow(window.scrollY > 200)
        }
        document.addEventListener("scroll", listener);
        return () => document.body.removeEventListener('scroll', listener); // 组件销毁后，取消监听
    }, [show])
    let goTop = () => {
        window.scrollTo(0, 0)
    }
    return show?<div className={style.topjumper} onClick={() => goTop()}>
        <VerticalAlignTopOutlined />
    </div>:null
}
export default TopJumper